//////////////////////////////////////////////////////////////////////////////////
//	Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#ifndef	__RT_SOCKET_YG_H__
#define __RT_SOCKET_YG_H__

#include "def.h"

class CRTSocket
{
public:
								CRTSocket(int nTimeOut=TICK_TIME);
								~CRTSocket(void);

	virtual void				Connect(const char* szAddress, unsigned short wPort);
	virtual int					Write(const  char* pData, size_t stSize);
	virtual int					Read( char* pData, size_t stSize);
	virtual void				Close();
	virtual void				Purge();
	virtual void				Login(const CONPARAMS& con) {}


	virtual bool				IsOk();
	virtual bool				IsConnected();
	virtual bool				WaitForRead(long milliseconds = 0);
	virtual bool				WaitForConnect(long milliseconds = CONNECT_TO_ROUTER_TIME_OUT);
	virtual wxString			GetEnterSeq() { return wxT(TELNET_ENTER_SEQ); }

	static void					Initialize();
	static bool					IsAddressEqual( const char* szAddr1, const char* szAddr2 );
	static struct addrinfo*		GetAddress( const char* szAddr, unsigned short wPort=23 );

	int							GetSockHandle() { return m_socket; }
	
protected:
	void						CheckError();

private:
	bool						m_bConnected;
	int							m_socket;
};

#endif //__RT_SOCKET_YG_H__